/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.colswedev.lab4.service;

import java.lang.reflect.InvocationTargetException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.colswedev.lab4.dao.GeneralDao;
import org.colswedev.lab4.entity.Rol;

/**
 *
 * @author James
 */
public final class RolService {
    
    private static RolService instance;
    private final GeneralDao dao;

    private RolService() {
        dao = new GeneralDao();
    }

    public static synchronized RolService getInstance(){
        if (instance==null){
            instance = new RolService();
        }
        return instance;
    }

    public List<Rol> getRoles() {
        List<Rol> roles = null;
        try {
            roles = dao.findAll(Rol.class);
        } catch (Exception ex) {
            Logger.getLogger(RolService.class.getName()).log(Level.SEVERE, "Ocurrio un error leyendo los roles disponibles.", ex);
        }
        return roles;
    }

    public Rol getRolById(int idRol) {
        Rol res = null;
        try {
            res = dao.getElement(idRol, Rol.class);
        } catch (Exception ex) {
            Logger.getLogger(RolService.class.getName()).log(Level.SEVERE, "Ocurrio un error leyendo el rol con id: " + idRol, ex);
        }
        return res;
    }

}
